package edu.sctu.fengleilin.month06.day150628.SecondPractice;


import com.alibaba.fastjson.JSONObject;

import java.io.*;


/**
* Created by user09 on 2015/6/28.
*/
public class JsonData implements Serializable{

    public  GoodsData getJsonData () {

        String json = "";
        byte[] bytes = new byte[1024];
        int count;
        try {
            FileInputStream fileInputStream = new FileInputStream(new File("D://json//json.txt"));
            try {
                while ((count = fileInputStream.read(bytes)) != -1){

                    json = json+ new String(bytes,0,count);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }



        GoodsData goodsData = JSONObject.parseObject(json, GoodsData.class);
        return goodsData;
    }

    public GoodsData writeData() throws Exception{

            FileOutputStream fout = new FileOutputStream("D://json//Appbean.txt");
            ObjectOutputStream out = new ObjectOutputStream(fout);
            out.writeObject(getJsonData());
            out.flush();
            out.close();

            FileInputStream fis = new FileInputStream("D://json//Appbean.txt");
            ObjectInputStream ois = new ObjectInputStream(fis);
            GoodsData goodsData =  (GoodsData)ois.readObject();
            ois.close();

            return goodsData;
    }
    public void judge() throws Exception {
        int count = 0;
        int count1 = 0;
        for (int i = 0; i <writeData().list.size(); i++) {
            double price =Double.parseDouble( getJsonData().list.get(i).goods_price);

            if (price>100){
                count++;

            }else{
                count1++;
            }
        }
        System.out.println("价格大于100的商品数量："+count);
        System.out.println("价格小于100的商品数量："+count1);
    }


}




